package query;

import index.HashIndex;
import global.Minibase;
import parser.AST_DropIndex;

/**
 * Execution plan for dropping indexes.
 */
class DropIndex implements Plan {

	String indexFileName;
//	Schema schema;
	
	/**
	 * Optimizes the plan, given the parsed query.
	 * 
	 * @throws QueryException
	 *             if index doesn't exist
	 */
	public DropIndex(AST_DropIndex tree) throws QueryException {
		indexFileName = tree.getFileName();
	    QueryCheck.indexExists(indexFileName);
	    

	} // public DropIndex(AST_DropIndex tree) throws QueryException

	/**
	 * Executes the plan and prints applicable output.
	 */
	public void execute() {

		// print the output message
		// delete the heap file and catalog entry
		HashIndex hashIdx = new HashIndex(indexFileName);
		hashIdx.deleteFile();

		Minibase.SystemCatalog.dropIndex(indexFileName);

		System.out.println("Index Dropped ");

	} // public void execute()

} // class DropIndex implements Plan
